package com.example.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.example.domain.FoodManagement;
import com.example.service.IFoodManagementService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 菜品汇总Controller
 * 
 * @author 何曼伶
 * @date 2024-09-13
 */
@RestController
@RequestMapping("/summary_dishes")
public class FoodManagementController extends BaseController
{
    @Autowired
    private IFoodManagementService foodManagementService;

    /**
     * 查询菜品汇总列表
     */
    @RequiresPermissions("food:summary_dishes:list")
    @GetMapping("/list")
    public TableDataInfo list(FoodManagement foodManagement)
    {
        startPage();
        List<FoodManagement> list = foodManagementService.selectFoodManagementList(foodManagement);
        return getDataTable(list);
    }

    /**
     * 导出菜品汇总列表
     */
    @RequiresPermissions("food:summary_dishes:export")
    @Log(title = "菜品汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FoodManagement foodManagement)
    {
        List<FoodManagement> list = foodManagementService.selectFoodManagementList(foodManagement);
        ExcelUtil<FoodManagement> util = new ExcelUtil<FoodManagement>(FoodManagement.class);
        util.exportExcel(response, list, "菜品汇总数据");
    }

    /**
     * 获取菜品汇总详细信息
     */
    @RequiresPermissions("food:summary_dishes:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(foodManagementService.selectFoodManagementById(id));
    }

    /**
     * 新增菜品汇总
     */
    @RequiresPermissions("food:summary_dishes:add")
    @Log(title = "菜品汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FoodManagement foodManagement)
    {
        return toAjax(foodManagementService.insertFoodManagement(foodManagement));
    }

    /**
     * 修改菜品汇总
     */
    @RequiresPermissions("food:summary_dishes:edit")
    @Log(title = "菜品汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FoodManagement foodManagement)
    {
        return toAjax(foodManagementService.updateFoodManagement(foodManagement));
    }

    /**
     * 删除菜品汇总
     */
    @RequiresPermissions("food:summary_dishes:remove")
    @Log(title = "菜品汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(foodManagementService.deleteFoodManagementByIds(ids));
    }
}
